var recordIndex=0;			//第几条成批记录,1表示带班领导的成批，2表示值班领导的成批，3表示总指挥的成批

var ppId = "";

var UId = "";

var mode="";


var ctag="0";

$(document).ready(function(){
	
	//selectPlanLevel();//选择预案等级
	//开始预案对话框
	$("#dialog").dialog("destroy");
	$("#dialog-form").dialog({
		autoOpen: false,
		width: 460,
		modal: true,
		resizable: false,
	    close: function() {
			$("#user-form input").removeClass('invalid');
			$("#user-form label").remove('.invalid');
			
			//test1;
			var myFileArr=window.frames["uploadFrame"].getFileArray();
			$.each(myFileArr,function(i,n){
				var htmlStr="";
				htmlStr+="<div><img src='lzm/images/doc.gif'/><span class='fn'>"
				htmlStr+=n.originName;
				htmlStr+="</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
				htmlStr+="<span class='crtName' style='display:none;'>";
				htmlStr+=n.crtName;
				htmlStr+="</span><span class='dell'>删除</span></div>";
				$('#paListDIV').append(htmlStr);
			});
			$('#planb').val(goodFileAnnex());	
			$('#pland').val(goodFileAnnex1());
			$('.dell').unbind("click");
			$('.dell').click(function () {
				$(this).parent().remove();
				$('#planb').val(goodFileAnnex());//键
				$('#pland').val(goodFileAnnex1());//真实名字	
			});
			//alert(myFileArr.length);
			//getPaList();
	 	}
	});
	$('#add_pro_annex')
		.click(function() {
			$('#dialog-form').dialog('open');
	});
	$('#backInput')
		.click(function() {
			history.go(-1);
	});
	//结束预案对话框
	
    if ($('#reportTag').text() == 'succ') {
        //alert("fdgdfgdf");
        $('#addSucc').show('slow');
        setTimeout(operateSucc, 3000);
    }
	mode=$('#mode').text();
	if(mode=="command"){
		//alert("gggggggggggggggggggggggggggggg");
		$('#backTR').show();
	}
	 
    //alert($('#reportTag').text());
    getCurrentTime();
    
    findUserInfo1();  
    findEventByID();
   
    selectPlanLevel(); //选择预案启动标准
    showLastTimeInfo();//上次处理建议
   
    findEventPropose();//查询呈批实体
    //findReportTableEnt();
    //alert("dfgdfg");
    $('#sureZhzrm').click(function(){
        setEventPlan2Session();
    });
    $('#spanPlanR').click(function(){
        //setEventPlan2Session();
        //alert("dfgdfgdf");
        //$("input[name='planRadio']:checked").checked=false;
        //$('input[@name=planRadio]').get(1).checked = false;
        // var $selectedvalue = $("input[name='planRadio']:checked").val();
        //$('#cacelCheckBox').click(cancelCheckBox);
        $("[name='planRadio']:checked").attr("checked", false);
    });
    /**
     * 开始对话框监听
     */
    $("#dialog").dialog("destroy");
    $("#dialog-form").dialog({
        autoOpen: false,
        width: 460,
        modal: true,
        resizable: false,
        close: function(){
            $("#user-form input").removeClass('invalid');
            $("#user-form label").remove('.invalid');
            getPaList();
        }
    });
    $('#add_propose_annex').click(function(){
        $('#dialog-form').dialog('open');
    });
    $('#enterPro').click(function(){
        //window.location.href="rating.jsp";
        checkEventAdmin();
    });
    /**
     * 添加处理意见按钮
     */
    $('#addPro').toggle(function(){
        $('#addPro').val("《《添加处理意见");
        $('#helpBD').show();
    }, function(){
        $('#addPro').val("添加处理意见》》");
        $('#helpBD').hide();
    });
    $('.addPropose4dbld').click(function(){
    	//根据事件状态默认选择的人物
    	if($("#tbesEventStatus").text()=="事件接报"){
    		$(this).attr("id","1004");
    	}else{
    		$(this).attr("id","1005");
    	}
    	
    	$("#deptul").empty();
    	$("#selDepts").empty();
		findAllDeptType();
		
				$("#selDepts").empty();
		$("#subDepts").empty();
		if($(this).attr("id")!=undefined&&$(this).attr("id")!="")//判断元素的id是否有值
	{
			var tmp_num=parseInt($(this).attr("id"));
			var tmp_str=parseInt($(this).attr("id")).toString();// 判断是否是角色的ID
			if(tmp_str!="NaN"&&tmp_num>=1000&&tmp_num<=1020)
		{
			default_role=$(this).attr("id");//如果角色是数字的话赋值给d_r
			$("#roleList option[value="+default_role+"]").attr("selected",true);//选中角色
			$.ajax({  //对应 default_role左边框的人员
		         type: "post",
		         url: "admin/queryUser_query.action",
		         data:{
			     "queryOption['URole']": default_role
		         },
		         success: function(data){
			$("#subDepts").empty();
			$.each(data.pageUtil.list, function(i, n){
				$("#subDepts").append("<option value=" + n.UId + ">" + n.UName + "</option>");
			 });
		     }
	         });//ajax
		}else{ //如果$(this).attr("id")为string
				$("#roleList option[value='noselect']").attr("selected",true);//选择 “请选择”
			 }
			
	}else{ //如果$(this).attr("id")为空
				$("#roleList option[value='noselect']").attr("selected",true);//选择 “请选择”
		 }
    	
		if($('#PComments').val()==""){
			alert("请填写呈批意见！");
			return;
		}
		/*
		if($('#targetAdmin1').text()==""){
			alert("请选择要呈批目标领导！");
			return;
		}*/
		//alert($("input[name='planRadio']:checked").val());
        //savePropose($(this));
		ctag="1";
		//alert("gggggggggggggggggggggggggggggggg");
		$("#leaderChooseWindow").dialog("open");
    });
});

function goodFileAnnex1(){
	var aa=1;
	var fileStr="";
	$('#paListDIV .fn').each(function(i,n){
		//alert(n.tbRole.RName);
		//uRoles[i] = "  "+n.tbRole.RName ;
		//alert($(this).text());
		if(aa==1){
			aa=2;
		}else{
			fileStr+=",";
		}
		fileStr+=$(this).text();
	});
	return fileStr;
}

function goodFileAnnex(){
	var aa=1;
	var fileStr="";
	$('#paListDIV .crtName').each(function(i,n){
		//alert(n.tbRole.RName);
		//uRoles[i] = "  "+n.tbRole.RName ;
		//alert($(this).text());
		if(aa==1){
			aa=2;
		}else{
			fileStr+=",";
		}
		fileStr+=$(this).text();
	});
	return fileStr;
}


/**
 * 作增加呈批
 */
function savePropose(rr){
    //alert("gggg454545");
    /*
     var EId = getCookie(eventId);
     var url = 'work2/LZMReport_savePropose.action';
     var params = {
     'proposes.tbUserByPViceCommander.UId': 'ag',
     'proposes.tbUserByPTeamLeader.UId': 'jfry',
     'proposes.tbUserByPCommander.UId': 'zhz',
     'proposes.tbEvent.EId': EId,
     'proposes.c': $('#c').attr('value'),
     //下面是部门
     'proposes.tbUserDeptByPImplementPlan.udId': 'CR0102000000',
     'proposes.tbUserDeptByPAssistDept.udId': 'CR0101000000',
     //下面是呈批记录
     'proposeRecord.PComments': $('#PComments').attr('value')
     };
     jQuery.post(url, params, saveProposeRst, 'json');
     */
    //开始指挥长 ，有1为ID，没有1为名字
	//rr.attr('disabled',"true");
    var a = $('#tbUserByPCommander').text();
    var b = $('#tbUserByPViceCommander').text();
    var c = $('#tbUserByPTeamLeader').text();
    var d = $('#tbUserDeptByPImplementPlan').text();
    var e = $('#tbUserDeptByPAssistDept').text();
	var houe=$("input[name='planRadio']:checked").val();
	
//    var a = $('#tbUserByPCommander1').text();
//    var b = $('#tbUserByPViceCommander1').text();
//    var c = $('#tbUserByPTeamLeader1').text();
//    var d = $('#tbUserDeptByPImplementPlan').text();
//    var e = $('#tbUserDeptByPAssistDept1').text();
//	var houe=$("input[name='planRadio']:checked").val();
	
	
    //alert(a);
    //结束指挥长
    //alert($('#targetAdmin1').text());
    var tdsp = "";
    tdsp += $('#targetDeptSP').text();
    tdsp += ",";
    tdsp += $('#targetDeptSP1').text();
    
    var EId = getCookie(eventId);
    var url = 'work2/LZMReport_saveProposeRecord.action';
    var params = {
        /*
         'proposeRecord.c': '0',
         'proposeRecord.a': tdsp,
         //'proposeRecord.b': 'dbld',
         'proposeRecord.tbUserByPrCheckId.UId': 'dbld',
         //'proposeRecord.tbUserByPrCheckId.UId': $('#targetAdmin1').text(),
         'proposeRecord.PViceCommander': 'ag',
         'proposeRecord.PTeamLeader': 'jfry',
         'proposeRecord.PCommander': 'zhz',
         'proposes.tbEvent.EId': EId,
         'proposes.ppId': ppId,
         //'proposes.c': $('#c').attr('value'),
         //下面是部门
         'proposeRecord.PImplementPlan': 'CR0102000000',
         'proposeRecord.PAssistDept': 'CR0101000000',
         //下面是呈批记录
         'proposeRecord.PComments': $('#PComments').attr('value')*/
        'proposeRecord.c': '0',
        'proposeRecord.a': tdsp,
        //'proposeRecord.b': 'dbld',
        //'proposeRecord.tbUserByPrCheckId.UId': 'dbld',
        //'proposeRecord.tbUserByPrCheckId.UId': $('#targetAdmin1').text(),
		'proposeRecord.tbUserByPrCheckId.UId': rr,
        'proposeRecord.PViceCommander': b,
        'proposeRecord.PTeamLeader': c,
        'proposeRecord.PCommander': a,
        'proposes.tbEvent.EId': EId,
        'proposes.ppId': ppId,
        //'proposes.c': $('#c').attr('value'),
        //下面是部门
        'proposeRecord.PImplementPlan': d,
        'proposeRecord.PAssistDept': e,
        //下面是呈批记录
        'proposeRecord.PComments': $('#PComments').attr('value'),
		//下面是预案等级建议
		'proposeRecord.e':houe,
		//下面是附件
		'proposeRecord.f':$('#planb').val(),
		'proposeRecord.g':$('#pland').val()
    };
    //alert(params+"cool");
    jQuery.post(url, params, saveProposeRst, 'json');
}

/**
 * 作增加呈批回调函数
 */
function saveProposeRst(data){
	
    if (data.ajaxRst == "success") {
    	saveToFomalPropose8();
        //window.location.href = "reportTable.jsp?reportTag=succ";
    }
    else {
        alert("失败，请重试！");
    }
    //
    //alert(data.ajaxRst);
}

/*
	 * 存储到正式 的呈批表
	 */
	function saveToFomalPropose8(){
		var a=$('#tbUserByPCommander1').text();
		var b=$('#tbUserByPViceCommander1').text();
		var c=$('#tbUserByPTeamLeader1').text();
		var d=$('#tbUserDeptByPImplementPlan').text();
		var e=$('#tbUserDeptByPAssistDept1').text();
		
		//alert(a+" "+b+" "+c+" "+d+" "+e);
		//alert("the same");
		setTimeout(function(){
			saveAdmin8(a,b,c,d,e);
			},1000);
		//alert(a+" "+b+" "+c+" "+d+" "+e);
	}
	
function saveAdmin8(a,b,c,d,e){
	//alert("gggg454545");
	//alert(b);	
    var EId = getCookie(eventId);
    var url = 'work2/LZMReport_saveAdmin.action';
    var params = {
        'proposes.tbUserByPViceCommander.UId': b,
        'proposes.tbUserByPTeamLeader.UId': c,
        'proposes.tbUserByPCommander.UId': a,
        'proposes.tbEvent.EId': EId,
		//下面是部门
		'proposes.e': d,
		'proposes.tbUserDeptByPAssistDept.udId': e
    };
    jQuery.post(url, params, saveAdminRstZRT8, 'json');
}
	
/**
 * 作增加呈批回调函数
 */
function saveAdminRstZRT8(data){
	if (data.ajaxRst == "success") {
		//alert("OK");
		//window.location.href="reportTable.jsp?reportTag=succ";
		//checkEmergency();
		//setEventPlan2SessionNoPlan();
		//setCookie(BACK_URL,"event_query_start.jsp")
		//window.location.href="operate_succ.jsp";
		//window.location.href="/ag/work/operate_rst_noplan.jsp";
		window.location.href="reportTable.jsp?reportTag=succ";
	}else{
		alert("失败，请重试！");
	}	
    //
    //alert(data.ajaxRst);
}


function operateSucc(){
    $('#addSucc').hide('slow');
}

/**
 * 查询事件实体
 */
function findEventByID(){
    //alert("dfgfd");
    var timestamp = Date.parse(new Date());
    $.get("work2/LZMReport_findEventByID.action?ts=" + timestamp + "&EId=" + getCookie(eventId), null, findEventByIDRst);
}

/**
 * 查询事件回调函数
 */
function findEventByIDRst(data){
    if (data.ajaxRst == "success") {
        $('#EEventname').text(data.event.EEventname);
        $('#EId').text(data.event.EId);
        $('#tbesEventStatus').text(data.event.tbEventStatus.tbesEventStatus);
        $('#tbesEventLevel').text(data.event.tbEventLevel.elEventLevel);//事件等级
        $('#EEventCause').text(data.event.EEventCause);
        $('#EEventDesc').text(data.event.EEventDesc);
        
        var ETakeMeasure = data.event.ETakeMeasure;
        if (ETakeMeasure == null) 
            ETakeMeasure = "暂无";
        $('#ETakeMeasure').text(ETakeMeasure);
        $('#tbEventSource').text(data.event.tbEventSource.esEventSource);
    }
    else {
        alert("失败，请重试 ！");
    }
}

/**
 * 查询呈批实体
 */
function findEventPropose(){
    var timestamp = Date.parse(new Date());
    $.get("work2/LZMReport_findEventPropose.action?ts=" + timestamp + "&EId=" + getCookie(eventId), null, findEventProposeRst);
   
}

/**
 * 查询呈批实体回调函数
 */
function findEventProposeRst(data){
    //alert("fdgfdgfdg");
    //alert(data.proposes==null);
	//alert(getCookie(eventId));
	//alert("ggggggggggggggggggggggggg456");
	
    if (data.proposes != null && data.ajaxRst == "success") {
    	
		//alert("ggggggggggggggggggggggggg4567");
        //$('#adminSP').text(data.tbUser.UName);
        //alert("7978798");
        //$('#EEventCause').val(data.proposesList[0].tbEvent.EEventCause);
        //$('#EEventCause').val(data.proposes.tbEvent.EEventCause);
        /*
         $('#EEventCause').val(data.proposes.tbEvent.EEventCause);
         $('#EEventDesc').val(data.proposes.tbEvent.EEventDesc);
         $('#ETakeMeasure').val(data.proposes.tbEvent.ETakeMeasure);
         $('#tbEventSource').text(data.proposes.tbEvent.tbEventSource.esEventSource);
         */
        /*
         $('#tbUserByPCommander').text(data.proposes.tbUserByPCommander.UName);
         $('#tbUserByPViceCommander').text(data.proposes.tbUserByPViceCommander.UName);
         $('#tbUserByPTeamLeader').text(data.proposes.tbUserByPTeamLeader.UName);
         $('#tbUserDeptByPImplementPlan').text(data.proposes.tbUserDeptByPImplementPlan.udName);
         $('#tbUserDeptByPAssistDept').text(data.proposes.tbUserDeptByPAssistDept.udName);
         $('#c').val(data.proposes.c);*/
        //alert(data.proposes.ppId);
        setCookie(ppId, data.proposes.ppId);
        ppId = data.proposes.ppId;
		
        /**
         * 下面是呈批审批情况
         */
      
     //   alert("成批："+data.proposes);
        if((typeof data.proposes)=="undefined")
        {
        	alert("undefined1");
        }
        else
        if((typeof data.proposes.tbProposeRecords)=="undefined") 
        {
        	$('#deptSP1').text("带班领导意见");
        	$('#deptSP1').show();
        //	alert("带班领导");
        }
        else if(data.proposes.tbProposeRecords.length==1)
        {
        	$('#deptSP1').text("值班领导意见");
        	$('#deptSP1').show();
        //	alert("值班领导");
        }
        else
        	if(data.proposes.tbProposeRecords.length>=2)
        	{
        	//	alert("指挥长");
        		$('#deptSP1').text("总指挥意见");
        		$('#deptSP1').show();
        		$('#tiaojiaochengpi').hide();
        		
        	}
       // alert("data.proposes.tbProposeRecords.length:"+data.proposes.tbProposeRecords.length);
        $.each(data.proposes.tbProposeRecords, function(i, n){
            //alert(n.tbUserByPrId.tbUserDepts[0].udName);
            //fillDatatoHTML(n.tbUserByPrId.UName,n.PComments);
			//alert("oooooooooooooooooo");
           // fillDatatoHTML(n.tbUserByPrId.tbUserDepts[0].udName, n.PComments, n.tbUserByPrId.UName, n.tbUserByPrId.UId, n.a, n.b, n.c, n.newPpId, n.tbUserByPrCheckId.UId, n.tbUserByPrCheckId.UName, n.PViceCommander, n.PTeamLeader, n.PCommander, n.PImplementPlan, n.PAssistDept,n.paTime,n.d,n.e);
		   //alert(data.proposes.b);		   
       		 fillDatatoHTML(n.tbUserByPrId.tbUserRoles[0].tbRole.RName, n.PComments, n.tbUserByPrId.UName, n.tbUserByPrId.UId, n.a, n.b, n.c, n.newPpId, n.tbUserByPrCheckId.UId, n.tbUserByPrCheckId.UName, n.PViceCommander, n.PTeamLeader, n.PCommander, n.PImplementPlan, n.PAssistDept,n.paTime,n.d,n.e,n.f,n.g,data.proposes.b,data.proposes.c,data.proposes.d);
	    });
 
        
    }
    else if (data.ajaxRst == "exception") {
        alert("失败，请重试，请检查后重试 ！");
    }
    else
    {
    	$('#deptSP1').text("带班领导意见");
    }
}

/**
 * DOM操作，动态生成HTML来显示内容
 * 参数：
 * bumen:  角色
 * yijian:  意见
 */
function fillDatatoHTML(bumen, yijian, xingming, uuUId, a, b, c, newPpId, tbUserByPrCheckId, cplindao, PViceCommander, PTeamLeader, PCommander, PImplementPlan, PAssistDept,paTime,d,e,f,g,dpb,dpc,dpd)
{
  //	alert("bumen: "+bumen+"\nyijian:"+yijian+"\nxingming:"+xingming+"\nc:"+c+"\nf:"+f+"\ng:"+g+"\nrecordIndex:"+recordIndex);
	recordIndex=recordIndex+1;
 //   alert("全局变量："+recordIndex);
	if(recordIndex==1) bumen="带班领导"
	else if(recordIndex==2) bumen = "值班领导";
	else if(recordIndex==3) bumen="总指挥";
	else if(recordIndex>=3) bumen="总指挥";
    //alert("dfgdgd");
    //alert(uuUId);
    //alert(UId);
    //alert(tbUserByPrCheckId);
    //alert(b);
    //alert(bumen);
	//alert(c);
	
	if(c=="8"){
		//alert("gc==8");
		var tempObjTR1 = null;
   		tempObjTR1 = $("#trCacheDirect").clone(true);
		var tempObj1 = null;
   		tempObj1 = tempObjTR1;		
		tempObj1.find('.bumen').text(bumen+"意见");
		tempObj1.find('.xingming').text(xingming);
    	tempObj1.find('.submitTime').text(b);
		tempObj1.find('.yijian').text(yijian);
		tempObj1.find('.cplindao').text(cplindao);
		//呈批附件
		var queryHtml="<span class='downReport' style='text-decoration:underline;color:#039;cursor:pointer;'>";
		queryHtml+=g;
		queryHtml+="</span>";
		queryHtml+="<span style='display:none'>";
		var url="/ag/file/download.action?fileRealName="+g+"&fileDiskURL="+f+"&moduleID=108";
		queryHtml+=url;
		queryHtml+="</span>"
		//tempObj.find('.cpfj').append(queryHtml);
		tempObj1.find('.cpfj').append(queryHtml);
		$('#helpTBODY').prepend(tempObj1);
		$('#helpTBODY').show();
		tempObjTR1 = null;	
		$('.downReport').click(function(){
			window.location.href=$(this).next().text();
		});
		return;
	}
	if(c=="7"){
		var tempObjTR1 = null;
   		tempObjTR1 = $("#trCache1").clone(true);
		var tempObj1 = null;
   		tempObj1 = tempObjTR1;
		
		tempObj1.find('.bumen').text(bumen+"意见");
		tempObj1.find('.xingming').text(xingming);
    	tempObj1.find('.submitTime').text(b);
		tempObj1.find('.yijian').text(yijian);
		tempObj1.find('.cplindao').text(cplindao);
		$('#helpTBODY').append(tempObj1);					//万才改过的
		$('#helpTBODY').show();
		tempObjTR1 = null;
		return;
	}
    
    
    var tempObjTR = null;
    tempObjTR = $("#trCache").clone(true);
    var tempObj = null;
    tempObj = tempObjTR;
    //tempObj = deepClone(tempObjTR);
    
    
    tempObj.find('.bumen').text(bumen+"意见");
    tempObj.find('.yijian').text(yijian);
    tempObj.find('.xingming').text(xingming);
    tempObj.find('.submitTime').text(b);
    if (a != null) {
        var atmp = a.split(",");
        tempObj.find('.cpbumen').text(atmp[0]);
    }
    tempObj.find('.cplindao').text(cplindao);
    /**
     * 下面显示事件指挥配置信息
     */
	//alert(PImplementPlan.replace(/(^\s*)|(\s*$)/g,"").length);
	tempObj.find('.jyqdyadj').hide();
	//alert("ffffffffffffffffffffff");
	//tempObj.find('.yjxzbm888').hide();
	tempObj.find('.yjbmxz').hide();
	tempObj.find('.jyzzh').hide();	
	tempObj.find('.yjzhz').hide();
	tempObj.find('.yjzz').hide();
	tempObj.find('.yjyabm').hide();
	tempObj.find('.cpfjdiv').hide();
	tempObj.find('.cpfj').children().remove();
	
	/*
	if(PViceCommander=="") PViceCommander="无";
	if(PTeamLeader=="") PTeamLeader="无";
	if(PCommander=="") PCommander="无";
	if(PImplementPlan!=null&&PImplementPlan.replace(/(^\s*)|(\s*$)/g,"").length==0) PImplementPlan="无";
	if(PAssistDept!=null&&PAssistDept.replace(/(^\s*)|(\s*$)/g,"").length==0) PAssistDept="无";
	*/
	if(f!=null){
		//tempObj.find('.cpfj').hide();
		tempObj.find('.cpfjdiv').show();
		var queryHtml="<span class='downReport' style='text-decoration:underline;color:#039;cursor:pointer;'>";
		queryHtml+=g;
		queryHtml+="</span>";
		queryHtml+="<span style='display:none'>";
		var url="/ag/file/download.action?fileRealName="+g+"&fileDiskURL="+f+"&moduleID=108";
		queryHtml+=url;
		queryHtml+="</span>"
		tempObj.find('.cpfj').append(queryHtml);
		
		
	}
	if(PViceCommander!=""){
		tempObj.find('.yjzhz').show();
		tempObj.find('.PViceCommander').text(PViceCommander);
	}
	if(PCommander!=""){
		tempObj.find('.jyzzh').show();
		tempObj.find('.PCommander').text(PCommander);		
	}
	if(PTeamLeader!=""){
		tempObj.find('.yjzz').show();
		tempObj.find('.PTeamLeader').text(PTeamLeader);		
	}
	if(PImplementPlan!=null&&PImplementPlan.replace(/(^\s*)|(\s*$)/g,"").length!=0){
		tempObj.find('.yjyabm').show();
		tempObj.find('.PImplementPlan').text(PImplementPlan);		
	}
	if(PAssistDept!=null&&PAssistDept.replace(/(^\s*)|(\s*$)/g,"").length!=0){
		tempObj.find('.yjbmxz').show();
		//alert("ggggggggggggggg");
		//alert(PAssistDept);
		tempObj.find('.PAssistDept').text(PAssistDept);		
	}
	
    
    //tempObj.find('.PTeamLeader').text(PTeamLeader);
    
    //tempObj.find('.PImplementPlan').text(PImplementPlan);
    //tempObj.find('.PAssistDept').text(PAssistDept);
	//alert(f);
	//alert(g);
	var aa="没有预案建议";
	switch(e){
		case "1":
			aa="Ⅰ级预案";
			tempObj.find('.planLevel').text(aa);
			break;
		case "2":
			aa="Ⅱ级预案";
			tempObj.find('.planLevel').text(aa);
			break;
		case "3":
			aa="Ⅲ级预案";
			tempObj.find('.planLevel').text(aa);
			break;
		case "4":
			aa="Ⅳ级预案";
			tempObj.find('.planLevel').text(aa);
			break;
		default:
			//aa="没有预案建议";
			break;
	}
	//tempObj.find('.planLevel').text(aa);	
    //$('#proposeTable').append(tempObj);
    //alert("dfgfdgfdgfdgfdgfd");
    //tempObj.prepend('#helpTBODY');
    //未审核
    //tempObj.find('.noCheckSP').hide();
	//与未批示一起
	//tempObj.find('.modify').hide();	
	//tempObj.find('.checkSuccSP').hide();
	tempObj.find('.psyjDIV').hide();
	//tempObj.find('.auditDiv').hide();
	
	//开始显示基本信息
	/*
	tempObj.find('.psyjDIV').show();
    tempObj.find('.psr').text(cplindao);
    tempObj.find('.pssj').text(b.replace(/T/," "));
    tempObj.find('.psyjyj').text(d);*/
	//结束显示基本信息
	//alert(dpb);
	//alert(uuUId);
	//alert(dpb==uuUId);
	tempObj.find('.modifydiv').hide();
	if(mode!="command"&&dpd==newPpId&&uuUId == UId&&dpb==UId&&dpc!='1'){
		//alert("gggggggggggggggg");
		tempObj.find('.modifydiv').show();
		tempObj.find('.ppid').text(newPpId);
	}
    
    
    $('#helpTBODY').prepend(tempObj);
	$('.modify').unbind("click");
    $('.modify').click(function(){
		cancelPropose($(this).next().text());
		//auditPropose(aud, $(this).next().text(), $(this).parent().parent().find('.checkComm').val())
	});
    $('.auditBtn').unbind("click");
    $('.auditBtn').click(function(){
        //alert($(this).parent($("input[type='radio']:checked")).val());
        //alert("fgdfgfdgdfgdfgdfgfd");
        //$("input[type='radio']:checked").val()
        //alert($(this).prev($("input[type='radio']:checked")).val());
        //var v=$(this).parent().get(0);   
        //alert($("input[type='radio']:checked").val());
        //$(this).prev().children();
        
        //alert($(this).prev().children().get(0).checked);
        
        
        var aud; //成功代码
        if ($(this).parent().children().get(0).checked == true) {
            aud = 1;
        }
        else {
            aud = 2;
        }
        auditPropose(aud, $(this).next().text(), $(this).parent().parent().find('.checkComm').val());
        //alert(aud);
    
        //auditPropose(aud,$(this).next().text());  $("input[type='radio']:checked").val();
        //if()
        //alert($(this).parent().parent().find('.checkComm').val());
    
        //auditPropose($("input[type='radio']:checked").val(),$(this).parent().parent().find('.checkComm').val());正确代码
        //alert($(this).prev().children().html());
        //alert($("$(this).prev()>input[type='radio']:checked").val());
    
        //alert($(this).prev('input').attr('checked'));
    
        //attr(‘checked‘)
        //alert($(this).prev("input[type='radio']:checked").html());
        //auditPropose();
    });
    tempObj = null;
	
	$('.downReport').click(function(){
		window.location.href=$(this).next().text();
	});
}

/**
 * 作增加呈批
 */
function auditPropose(c, newPpId, PComments){
    //var EId = getCookie(eventId);
    //alert(c);
    //alert(newPpId);
    //alert(PComments);
    var url = 'work2/LZMReport_auditPropose.action';
    var params = {
        'proposeRecord.c': c,
        'proposeRecord.newPpId': newPpId,
        'proposeRecord.d': PComments,
		'EId':getCookie(eventId)
    };
    jQuery.post(url, params, auditProposeRst, 'json');
}

/**
 * 作增加呈批回调函数
 */
function auditProposeRst(data){
    if (data.ajaxRst == "success") {
        window.location.href = "reportTable.jsp?reportTag=succ";
    }
    else {
        alert("失败，请重试！");
    }
    //alert(data.ajaxRst);
}


/**
 * 作取消呈批
 */
function cancelPropose(newPpId){
    //var EId = getCookie(eventId);
    //alert(c);
    //alert(newPpId);
    //alert(PComments);
	//alert(newPpId);
	//alert(getCookie(eventId));
    var url = 'work2/LZMReport_cancelPropose.action';
    var params = {
        'proposeRecord.newPpId': newPpId,
		'EId':getCookie(eventId)
    };
    jQuery.post(url, params, cancelProposeRst, 'json');
}

/**
 * 作取消呈批回调函数
 */
function cancelProposeRst(data){
    if (data.ajaxRst == "success") {
        window.location.href = "reportTable.jsp?reportTag=succ";
    }
    else {
        alert("失败，请重试！");
    }
    //alert(data.ajaxRst);
}

/*
var cloneAll = function(_obj){
    var F = new Function();
    F.prototype = _obj;
    var obj = new F();
    for (var ele in obj) {
        if (typeof(obj[ele]) == "object") {
            obj[ele] = arguments.callee(obj[ele]);
        }
    }
    return obj;
}
function deepClone(object){ 
if(object == null) return null; 
if(("number boolean string undefined").indexOf((typeof object).toLowerCase()) >= 0) 
    return object;//值类型 直接返回 
if(object instanceof Array){ 
    var newArray = []; 
    for(var i=0;i<object.length;i++){ 
      newArray.push(arguments.callee(object[i])); 
    } 
    return newArray; 
} 
var obj = new Object(); 
for(var property in object){ 
    obj[property] = arguments.callee(object[property]); 
} 
return obj; 
}*/




function cancelCheckBox(){
    $("[name='planRadio']:checked").attr("checked", false);
}

function getCurrentTime(){
    var Timer = new Date();
    var years = Timer.getFullYear();
    var months = Timer.getMonth() + 1;
    var days = Timer.getDate();
    var hours = Timer.getHours();
    var minutes = Timer.getMinutes();
    var seconds = Timer.getSeconds();
    if (minutes <= 9) 
        minutes = "0" + minutes;
    if (seconds <= 9) 
        seconds = "0" + seconds;
    /*
     var dateTime = years + "-" + months + "-" + days + " " + hours
     + ":" + minutes + ":" + seconds;*/
    var dateTime = years + "-" + months + "-" + days;
    $("#dateTime").text(dateTime);
}

function findUserInfo(){
    var timestamp = Date.parse(new Date());
    $.get("admin/UserServ_findUserInfo.action?ts=" + timestamp, null, findUserInfoRst);
}

function findUserInfoRst(data){
    if (data.ajaxRst == "success") {
        $('#adminSP').text(data.tbUser.UName);
    }
}

function findUserInfo1(){
	 
    var timestamp = Date.parse(new Date());
    $.get("admin/UserServ_findUserInfo.action?ts=" + timestamp, null, findUserInfoRst1);
    
}

function findUserInfoRst1(data){
    if (data.ajaxRst == "success") {
        //var roleList=data.tbUser.tbUserRoles[0].tbRole.RName;
        //$('#roleSP').text(roleList);
        //var roleStr="";
        //$.each(data.tbUser.tbUserRoles,function(i,n){
        //fillDatatoHTML(n.PId,n.PName,n.tbPlanGrade.pgName,n.tbPlanStatus.pstName,n.tbPlanType.ptName);
        //alert(n.tbRole.RName);
        //roleStr+=n.tbRole.RName;
        //roleStr+="、";
        //});
        //alert(data.tbUser.tbUserRoles.length);
        //alert(data.tbUser.ULoginTime);
        
        UId = data.tbUser.UId;
        
        $('#adminSP').text(data.tbUser.UName);
        $('#adminSP1').text(data.tbUser.UName);
        $('#loginSP').text(data.tbUser.ULoginTime.replace(/T/, " "));
        var uRoles = new Array(data.tbUser.tbUserRoles.length);
		//var goo;
		//goo=parseInt(data.tbUser.tbUserRoles[0].tbRole.RId);
		//findAllRole(rolechooser,goo+1);//多角色格式如下：var rolechooser = "1001,1002";
		var goo;
		goo=parseInt(data.tbUser.tbUserRoles[0].tbRole.RId);
		//alert(goo);
		if(goo==1002){			
			findAllRole(rolechooser,1004);//多角色格式如下：var rolechooser = "1001,1002";
		}else if(goo==1004){			
			findAllRole(rolechooser,1005);//多角色格式如下：var rolechooser = "1001,1002";
		}else{
			findAllRole(rolechooser,goo+1);//多角色格式如下：var rolechooser = "1001,1002";
		}
        $.each(data.tbUser.tbUserRoles, function(i, n){
            //alert(n.tbRole.RName);
            uRoles[i] = "  " + n.tbRole.RName;
        });
        var strhtml = "";
        strhtml += uRoles;
        $('#roleSP').text(strhtml);
        /**
         * 下面是显示部门的信息
         */
        //alert(data.tbUser.tbUserDepts.length);
        var uDepts = new Array(data.tbUser.tbUserDepts.length);
        $.each(data.tbUser.tbUserDepts, function(i, n){
            //alert(n.tbUserDepts.udName);
            uDepts[i] = "  " + n.udName;
        });
        var strhtml1 = "";
        strhtml1 += uDepts;
        $('#deptSP').text(strhtml1);
        //$('#deptSP1').text(strhtml1);
	//	$('#deptSP1').text(strhtml+"意见");
		//$('#deptSP1').text("san");
    }
}

function showLastTimeInfo(){
	var url = "/ag/zrt/showLastTimeInfo.action";
	data = {};
	$.post(url,data,showFive);
}

function showFive(data){
	//alert("start");
	if(data.commander != null && data.commanderUid != null){
		//alert("1");
		$('#tbUserByPCommander').text(data.commander);
		$('#tbUserByPCommander1').text(data.commanderUid);
	}
	if(data.viceCommander != null && data.viceCommanderUid != null){
		//alert("2");
		$('#tbUserByPViceCommander').text(data.viceCommander);
		$('#tbUserByPViceCommander1').text(data.viceCommanderUid);
	}
	if(data.teamLeader != null && data.teamLeaderUid != null){
		//alert("3");
		$('#tbUserByPTeamLeader').text(data.teamLeader);
		$('#tbUserByPTeamLeader1').text(data.teamLeaderUid);
	}
	if(data.assistDept != null && data.assistDeptDid != null){
		//alert("4");
		$('#tbUserDeptByPAssistDept').text(data.assistDept);
		$('#tbUserDeptByPAssistDept1').text(data.assistDeptDid);
	}
	if(data.implementPlan != null){
		//alert("5");
		$('#tbUserDeptByPImplementPlan').text(data.implementPlan);
		//$('#tbUserByPTeamLeader1').text(data.teamLeaderUid);
	}

	if(data.counts == null) {
		$('#deptSP1').show();
		$('#curRole').hide();
	}
		
}

/*
 * 选择预案等级
 * @memberOf {TypeName} 
 */
function selectPlanLevel(){
	//alert("cool");
	$('[name=planRadio]').click(function(){
		var planlevelId=$(this).attr('id');
//			alert(planlevelId);
			
//			window.open("/ag/work/setPlanStandard.jsp?planLevel="+$(this).attr('value'), null,
//								"scrollbars = yes,resizable = yes");
			//以下为通过plan的等级来判断,由于锐童原来为one,two,three,four,现在要的参数为1,2,3,4
			var planLevel='1';
			switch(planlevelId){
			case 'one':planLevel='1';break;
			case 'two':planLevel='2';break;
			case 'three':planLevel='3';break;
			case 'four':planLevel='4';break;
			}
//			alert(planLevel);
			var url_updateEventLevel="/ag/dgm/updateEventLevel_DGMdisposalAdvice.action";
			$.post(url_updateEventLevel,{'eventLevel':planLevel},function(data){					//更新事件等级的				
			});
			window.location.href="/ag/work/setPlanStandard.jsp?planLevel="+$(this).attr('value'), null,
		"scrollbars = yes,resizable = yes";
	});
}
